<?php

namespace addons\member\model;

//用户收藏点赞表
class MemberCollect extends \web\common\model\BaseModel {

    protected function _initialize() {
        $this->tableName = 'member_collect';
    }

    public function getList($pageIndex = -1, $pageSize = -1, $filter = '', $order = 'id desc') {
        $sql = 'select * from ' . $this->getTableName();
        if (!empty($filter)) {
            $sql = $sql . ' where ' . $filter;
        }
        return $this->getDataListBySQL($sql, $pageIndex, $pageSize, $order);
    }


    public function collect($user_id,$collect_id,$type){
        $map['user_id'] = $user_id;
        $map['collect_type'] = $type;
        $map['collect_id'] = $collect_id;
        $res = $this->where($map)->find();
        if($res){
            return $this->where($map)->delete();
        }else{
            $map['create_time'] = NOW_DATETIME;
            return $this->add($map);
        }
    }

}
